package org.zfes.snowier.zbss.xzy.router.device;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.device.model.DeviceModel;
import org.zfes.snowier.zbss.xzy.biz.device.service.IDeviceModelService;
@Controller 
@RequestMapping("/manger/deviceModel")
public class DeviceModelController implements BaseController {

	
	@Autowired
	private IDeviceModelService deviceModelService;
	
    @RequestMapping(value="/loadDeviceModelDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadDeviceModelDataSet(@RequestParam Map<String,Object> params){
	    DataSet dataSet=  deviceModelService.loadDeviceModelDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
    
    @RequestMapping(value="/loadByDeviceType/{deviceTypeId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAllDeviceType(@PathVariable("deviceTypeId") Long deviceTypeId){
    	List<DeviceModel> deviceModelList  =  deviceModelService.loadByDeviceType(deviceTypeId, Byte.valueOf("1"));
	    return ajaxQuery("result", deviceModelList);
    }
    
    
    @RequestMapping(value="/createDeviceModel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody Object createDeviceModel(DeviceModel deviceModel){
		deviceModelService.createDeviceModel(deviceModel);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/loadDeviceModel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadDeviceModel(Long id){
		Optional<DeviceModel> ops = deviceModelService.loadDeviceModelById(id);
		return ajaxQuery("deviceModel",ops);
    }
	
    @RequestMapping(value="/updateDeviceModel", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object updateDeviceModel(DeviceModel deviceModel){
		deviceModelService.updateDeviceModel(deviceModel);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
    
    @RequestMapping(value="/setDeviceModelStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object setDeviceModelStatus(Long id,Byte status){
		deviceModelService.setDeviceModelStatus(id, status);
		return ajaxDoneSuccess("数据操作成功 ");
    }
    
}